package com.mm.dss.demo;

import android.app.Dialog;
import android.graphics.Color;
import android.os.Build;
import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
import android.util.Log;
import android.view.Gravity;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.AdapterView;
import android.widget.BaseAdapter;
import android.widget.RelativeLayout;
import android.widget.TextView;
import android.widget.Toast;


import com.bigkoo.pickerview.builder.OptionsPickerBuilder;
import com.bigkoo.pickerview.builder.TimePickerBuilder;
import com.bigkoo.pickerview.configure.PickerOptions;
import com.bigkoo.pickerview.listener.OnOptionsSelectChangeListener;
import com.bigkoo.pickerview.listener.OnOptionsSelectListener;
import com.bigkoo.pickerview.view.OptionsPickerView;
import com.bigkoo.pickerview.view.TimePickerView;
import com.github.mikephil.charting.animation.Easing;
import com.github.mikephil.charting.charts.LineChart;
import com.github.mikephil.charting.components.XAxis;
import com.github.mikephil.charting.components.YAxis;
import com.github.mikephil.charting.data.Entry;
import com.github.mikephil.charting.data.LineData;
import com.github.mikephil.charting.data.LineDataSet;
import com.github.mikephil.charting.formatter.IAxisValueFormatter;
import com.google.gson.Gson;
import com.lzy.okgo.model.Response;
import com.lzy.okgo.request.base.Request;
import com.mm.dss.demo.Interface.OkGoUtilsInterFace;
import com.mm.dss.demo.base.BaseActivity;
import com.mm.dss.demo.bean.JZBBean;
import com.mm.dss.demo.bean.JZBean;
import com.mm.dss.demo.bean.XxCjBean;
import com.mm.dss.demo.tools.Constances;
import com.mm.dss.demo.tools.OkgoUtils;
import com.mm.dss.demo.tools.SharedPreferencedUtils;
import com.mm.dss.demo.tools.SoftKeyboardUtils;
import com.mm.dss.demo.tools.TimeHepler;
import com.mm.dss.demo.tools.WebServiceUtils;
import com.mm.dss.demo.tools.WeiboDialogUtils;
import com.mm.dss.demo.view.DateChooseWheelViewDialog;
import com.mm.dss.demo.view.xFormatter;
import com.qmuiteam.qmui.util.QMUIDisplayHelper;
import com.qmuiteam.qmui.widget.popup.QMUIListPopup;
import com.qmuiteam.qmui.widget.popup.QMUIPopup;

import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;
import org.ksoap2.serialization.SoapObject;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import butterknife.BindView;
import butterknife.OnClick;

/*
 * 监测数据查询
 * */
public class SjcxActivity extends BaseActivity {
    TextView txt_title;
    RelativeLayout layout_back;
    private QMUIListPopup namelistpopup;//位置名称弹出框
    TextView stime, EndtTimeName, StartTimeName, monitoringPointsName, AddressName;
    TextView etime;
    LineChart mLineChart;
    IAxisValueFormatter xValueFormatter;
    ArrayList<String> xValueList = new ArrayList<>();
    ArrayList<Float> yValuelLst = new ArrayList<>();
    private ArrayList<JZBean> jzBeans = new ArrayList<>();
    private ArrayList<JZBBean> jzbBeans = new ArrayList<>();

    private LineDataSet set1;
    private String starttime = "2017-11-1 12:00:00";
    private String endtime = "2017-11-3 12:00:00";
    private Dialog mWeiboDialog;
    private JZBBean jzbBean;
    private Handler handler = new Handler() {
        @Override
        public void handleMessage(Message msg) {
            super.handleMessage(msg);
            switch (msg.what) {
                case 1:
                    //下拉刷新
//                    setnet();//网络请求
                    break;
            }
        }
    };

    private void setnet(JZBBean bean,String KSSJ,String JSSJ) {
        mWeiboDialog = WeiboDialogUtils.
                createLoadingDialog(SjcxActivity.this,
                        "加载中...");
        Map<String, String> map = new HashMap<>();
        map.put("KSSJ" ,KSSJ);
        map.put("JSSJ" ,JSSJ);
        String methodName = null;
        switch (getIntent().getStringExtra("type")){
            case "1":
                methodName="N16_GetGNSS";
                map.put("TJBH" ,bean.getZJDZ());
                break;
            case "2":
                methodName="N17_GetJYL";
                map.put("KJBH" ,bean.getSBBH());
                map.put("CXLX" ,"All");
                break;
            case "3":
                methodName="N18_GetNSL";
                map.put("KJBH" ,bean.getZJDZ());

                break;
            case "4":
                methodName="N19_GetDLF";
                map.put("KJBH" ,bean.getZJDZ());
                break;
        }

        WebServiceUtils.callWebService(Constances.webhosturl, methodName, map, new WebServiceUtils.WebServiceCallBack() {
            @Override
            public void callBack(SoapObject result) {
                WeiboDialogUtils.closeDialog(mWeiboDialog);
                Log.i("检车数据", result.getProperty(0).toString());
                try {
                    JSONArray array = new JSONArray(result.getProperty(0).toString());
                    xValueList.clear();
                    yValuelLst.clear();
                    if (array.length()>0){
//                        JSONObject jsonObject = array.optJSONObject(0);
//
//                        String xdatastr = jsonObject.optString("X");
//                        Log.i("检车数据==", xdatastr.toString());
//                        JSONArray xdata = new JSONArray(xdatastr);
//                        for (int i = 0; i < xdata.length(); i++) {
//                            xValueList.add(xdata.get(i).toString());
//                            Log.i("检车数据=xValueList--", xdata.get(i).toString());
//                        }
//                        Log.i("检车数据=xValueList", xValueList.toString());
//                        String ydatastr = jsonObject.optString("Y");
//                        JSONArray ydata = new JSONArray(ydatastr);
//                        for (int i = 0; i < ydata.length(); i++) {
//                            yValuelLst.add(Float.valueOf(ydata.get(i).toString()));
//                            Log.i("检车数据=xValueList--", ydata.get(i).toString());
//                        }
//                        Log.i("检车数据=yValuelLst", yValuelLst.toString());

                        switch (getIntent().getStringExtra("type")){
                            case "1":
                                for (int i = 0; i < array.length(); i++) {
                                    xValueList.add(array.optJSONObject(i).getString("TIME"));
                                    yValuelLst.add(Float.valueOf(array.optJSONObject(i).getString("H")));
                                }
                                initdata("沉降,(y轴偏移量,x轴日期)");
                                break;
                            case "2":
                                for (int i = 0; i < array.length(); i++) {
                                    xValueList.add(array.optJSONObject(i).getString("RFCOLTIME"));
                                    yValuelLst.add(Float.valueOf(array.optJSONObject(i).getString("RFNUMBER")));
                                }
                                initdata("降雨量,(y轴雨量,x轴日期)");

                                break;
                            case "3":
                                for (int i = 0; i < array.length(); i++) {
                                    xValueList.add(array.optJSONObject(i).getString("RECVTIME"));
                                    yValuelLst.add(Float.valueOf(array.optJSONObject(i).getString("ELECDATA")));
                                }
                                initdata("泥石流");
                                break;
                            case "4":
                                for (int i = 0; i < array.length(); i++) {
                                    xValueList.add(array.optJSONObject(i).getString("RECVTIME"));
                                    yValuelLst.add(Float.valueOf(array.optJSONObject(i).getString("ELECDATA")));
                                }
                                initdata("裂缝计");
                                break;
                        }
                    }

                } catch (JSONException e) {
                    e.printStackTrace();
                }
            }
        });
    }

    private void DropDownBoxA(){
        Map<String, String> map = new HashMap<>();
        map.put("i", getIntent().getStringExtra("type"));

        WebServiceUtils.callWebService(Constances.webhosturl, "N14_GetYHD", map, new WebServiceUtils.WebServiceCallBack() {
            @Override
            public void callBack(SoapObject result) {
                //                WeiboDialogUtils.closeDialog(mWeiboDialog);
                Gson gson=new Gson();
                Log.i("检车数据", result.getProperty(0).toString());
                try {
                    JSONArray array = new JSONArray(result.getProperty(0).toString());
                    for (int i=0;i<array.length();i++){
                        JZBean jzBean  =gson.fromJson(array.optJSONObject(i).toString(),JZBean.class);
                        jzBeans.add(jzBean);

                    }
                    AddressName.setText(jzBeans.get(0).getDZDMC());
                    DropDownBoxB(jzBeans.get(0).getDZDBH());
                } catch (JSONException e) {
                    e.printStackTrace();
                }
            }
        });
    }

    private void DropDownBoxB(String dzdbh){
        Map<String, String> map = new HashMap<>();
        map.put("i", getIntent().getStringExtra("type"));
        map.put("dzdbh", dzdbh);
        WebServiceUtils.callWebService(Constances.webhosturl, "N15_GetJCD", map, new WebServiceUtils.WebServiceCallBack() {
            @Override
            public void callBack(SoapObject result) {
                Gson gson=new Gson();
                Log.i("检车数据", result.getProperty(0).toString());
                jzbBeans.clear();
                try {
                    JSONArray array = new JSONArray(result.getProperty(0).toString());
                    for (int i=0;i<array.length();i++){
                        JZBBean jzbBean  =gson.fromJson(array.optJSONObject(i).toString(),JZBBean.class);
                        jzbBeans.add(jzbBean);

                    }
                    monitoringPointsName.setText(jzbBeans.get(0).getPickerViewText());
                    jzbBean=jzbBeans.get(0);
                    setnet(jzbBean,StartTimeName.getText().toString(),EndtTimeName.getText().toString());
                } catch (JSONException e) {
                    e.printStackTrace();
                }
            }
        });
    }
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_sjcx);
        if (getIntent().getStringExtra("type") == null) return;
        layout_back = (RelativeLayout) findViewById(R.id.layout_back);
//        txt_title= (TextView) findViewById(R.id.txt_title);
        stime = (TextView) findViewById(R.id.stime);
        etime = (TextView) findViewById(R.id.etime);
        mLineChart = (LineChart) findViewById(R.id.mylinechart);
        EndtTimeName = (TextView) findViewById(R.id.EndtTimeName);
        StartTimeName = (TextView) findViewById(R.id.StartTimeName);
        monitoringPointsName = (TextView) findViewById(R.id.monitoringPointsName);
        AddressName = (TextView) findViewById(R.id.AddressName);
//        txt_title.setText("监测数据");
        layout_back.setVisibility(View.VISIBLE);
//        setnet();
        time();
        DropDownBoxA();



    }


    protected void initdata(String label) {

        setChartProperties();

        xValueFormatter = new xFormatter(xValueList);
        setChartXAxis(xValueFormatter);
        setChartYAxis();
        setData1(xValueList, yValuelLst,label);

    }

    private void time() {
        long time = System.currentTimeMillis();
        Date date = new Date(time);
        EndtTimeName.setText(TimeHepler.getTOTime(date));
        StartTimeName.setText(getOldDate(-7));
    }

    /**
     * +   是N天后
     * -   是N天前
     *
     * @param distanceDay
     * @return
     */
    public static String getOldDate(int distanceDay) {
        SimpleDateFormat dft = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        Date beginDate = new Date();
        Calendar date = Calendar.getInstance();
        date.setTime(beginDate);
        date.set(Calendar.DATE, date.get(Calendar.DATE) + distanceDay);
        Date endDate = null;
        try {
            endDate = dft.parse(dft.format(date.getTime()));
        } catch (ParseException e) {
            e.printStackTrace();
        }
        return dft.format(endDate);
    }

    public void onclick(View view) {
        switch (view.getId()) {
            case R.id.etime:
                //结束时间
                DateChooseWheelViewDialog endateChooseDialog = new DateChooseWheelViewDialog(SjcxActivity.this,
                        new DateChooseWheelViewDialog.DateChooseInterface() {
                            @Override
                            public void getDateTime(String time, boolean longTimeChecked) {
                                Log.i("选择的时间", time);
                                endtime = time;
                                etime.setText("结束时间：" + time);
                                handler.sendEmptyMessageDelayed(1, 2000);
                            /*    btn_sj.setText(time);
                                date=time;
                                SharedPreferencedUtils.setString(DaoHangActivity.this,"dhdate",date);
                                xsgj();*/
                            }
                        });
                endateChooseDialog.setTimePickerGone(true);
                endateChooseDialog.setDateDialogTitle("结束时间");
                endateChooseDialog.showDateChooseDialog();
                break;
            case R.id.stime:
                //时间
                DateChooseWheelViewDialog startDateChooseDialog = new DateChooseWheelViewDialog(SjcxActivity.this,
                        new DateChooseWheelViewDialog.DateChooseInterface() {
                            @Override
                            public void getDateTime(String time, boolean longTimeChecked) {
                                Log.i("选择的时间", time);
                                starttime = time;
                                stime.setText("开始时间：" + time);
                            /*    btn_sj.setText(time);
                                date=time;
                                SharedPreferencedUtils.setString(DaoHangActivity.this,"dhdate",date);
                                xsgj();*/
                            }
                        });
                startDateChooseDialog.setTimePickerGone(true);
                startDateChooseDialog.setDateDialogTitle("开始时间");
                startDateChooseDialog.showDateChooseDialog();
                break;
            case R.id.xuanze:
                final List<String> list = new ArrayList();
                for (int i = 0; i < 100; i++) {
                    list.add(i + "");
                }
                if (namelistpopup == null) {
                    namelistpopup = new QMUIListPopup(this, QMUIPopup.DIRECTION_NONE,
                            new NameAdapter(list));
                    namelistpopup.create(QMUIDisplayHelper.getScreenWidth(this),
                            QMUIDisplayHelper.dp2px(this, 200),
                            new AdapterView.OnItemClickListener() {
                                @Override
                                public void onItemClick(AdapterView<?> adapterView, View view, int i, long l) {
                                    stime.setText(list.get(i));
                                    namelistpopup.dismiss();
                                }
                            });
                }
                namelistpopup.setAnimStyle(QMUIPopup.ANIM_GROW_FROM_CENTER);
                namelistpopup.setPreferredDirection(QMUIPopup.DIRECTION_TOP);
                namelistpopup.show(stime);
                break;
            case R.id.layout_back:
                finish();
                break;
            case R.id.LLStartTime:
                if (SoftKeyboardUtils.isSoftShowing(this)) {
                    SoftKeyboardUtils.hideSystemSoftKeyboard(this);
                }
                TimePickerView timePickerView = new TimePickerBuilder(this, (date, v1) -> {
                    StartTimeName.setText(TimeHepler.getTOTime(date));
                    setnet(jzbBean,StartTimeName.getText().toString(),EndtTimeName.getText().toString());
                }).setType(new boolean[]{true, true, true, true, true, true})
                        .setLabel("年", "月", "日", "时", "分", "秒")
                        .setGravity(Gravity.CENTER)
                        .setTitleText("开始时间")
                        .build();
                timePickerView.show();
                break;
            case R.id.LLEndtTime:
                if (SoftKeyboardUtils.isSoftShowing(this)) {
                    SoftKeyboardUtils.hideSystemSoftKeyboard(this);
                }
                TimePickerView timePickerView1 = new TimePickerBuilder(this, (date, v1) -> {
                    EndtTimeName.setText(TimeHepler.getTOTime(date));
                    setnet(jzbBean,StartTimeName.getText().toString(),EndtTimeName.getText().toString());
                }).setType(new boolean[]{true, true, true, true, true, true})
                        .setLabel("年", "月", "日", "时", "分", "秒")
                        .setGravity(Gravity.CENTER)
                        .setTitleText("结束时间")
                        .build();
                timePickerView1.show();
                break;
            case R.id.MonitoringPoints:
                OptionsPickerView pvOptions = new OptionsPickerBuilder(this, new OnOptionsSelectListener() {
                    @Override
                    public void onOptionsSelect(int options1, int options2, int options3, View v) {
                        //返回的分别是三个级别的选中位置
                        String tx = jzbBeans.get(options1).getPickerViewText()
                               /*  + jzBeans2.get(options1).get(options2)
                                 + options3Items.get(options1).get(options2).get(options3).getPickerViewText()*/;
//                        btn_Options.setText(tx);
                        monitoringPointsName.setText(jzbBeans.get(options1).getPickerViewText());
                        jzbBean=jzbBeans.get(options1);
                        setnet(jzbBean,StartTimeName.getText().toString(),EndtTimeName.getText().toString());
                    }
                })
                        .setTitleText("站点选择")
                        .setContentTextSize(20)//设置滚轮文字大小
                        .setSelectOptions(0, 0)//默认选中项
                        .isRestoreItem(true)//切换时是否还原，设置默认选中第一项。
                        .isCenterLabel(false) //是否只显示中间选中项的label文字，false则每项item全部都带有label。
                        .setLabels("", "", "")
//                        .setOptionsSelectChangeListener(new OnOptionsSelectChangeListener() {
//                            @Override
//                            public void onOptionsSelectChanged(int options1, int options2, int options3) {
//                                String str = "options1: " + options1 + "\noptions2: " + options2 + "\noptions3: " + options3;
//                                Toast.makeText(SjcxActivity.this, str, Toast.LENGTH_SHORT).show();
//                            }
//                        })
                        .build();

                pvOptions.setPicker(jzbBeans);//一级选择器
                pvOptions.show();
                break;
            case R.id.Address:
                OptionsPickerView pvOptionAddress = new OptionsPickerBuilder(this, new OnOptionsSelectListener() {
                    @Override
                    public void onOptionsSelect(int options1, int options2, int options3, View v) {
                        //返回的分别是三个级别的选中位置
                        AddressName.setText(jzBeans.get(options1).getPickerViewText());
                        DropDownBoxB(jzBeans.get(options1).getDZDBH());
                    }
                })
                        .setTitleText("站点选择")
                        .setContentTextSize(20)//设置滚轮文字大小
                        .setSelectOptions(0, 0)//默认选中项
                        .isRestoreItem(true)//切换时是否还原，设置默认选中第一项。
                        .isCenterLabel(false) //是否只显示中间选中项的label文字，false则每项item全部都带有label。
                        .setLabels("", "", "")
                        .build();

                pvOptionAddress.setPicker(jzBeans);//一级选择器
                pvOptionAddress.show();
                break;
        }
    }

    class NameAdapter extends BaseAdapter {
        //位置名称
        List<String> data;

        private NameAdapter(List<String> data) {
            this.data = data;
        }

        @Override
        public int getCount() {
            return data.size();
        }

        @Override
        public Object getItem(int position) {
            return data.get(position);
        }

        @Override
        public long getItemId(int position) {
            return position;
        }

        @Override
        public View getView(int position, View convertView, ViewGroup parent) {
            convertView = LayoutInflater.from(SjcxActivity.this).inflate(R.layout.item_spinner_view, null);
            TextView txt = (TextView) convertView.findViewById(R.id.txt);
            txt.setText(data.get(position));
            return convertView;
        }
    }

    private void setChartProperties() {
        //设置描述文本不显示
        mLineChart.getDescription().setEnabled(false);
        //设置是否显示表格背景
        mLineChart.setDrawGridBackground(true);
        //设置是否可以触摸
        mLineChart.setTouchEnabled(true);
        mLineChart.setDragDecelerationFrictionCoef(0.9f);
        //设置是否可以拖拽
        mLineChart.setDragEnabled(true);
        //设置是否可以缩放
        mLineChart.setScaleEnabled(true);
        mLineChart.setDrawGridBackground(false);
        mLineChart.setHighlightPerDragEnabled(true);
        mLineChart.setPinchZoom(true);
        //设置背景颜色
        mLineChart.setBackgroundColor(Color.parseColor("#ffffff"));
        //设置一页最大显示个数为12，超出部分就滑动
        float ratio = (float) xValueList.size() / (float) 25;
        //显示的时候是按照多大的比率缩放显示,1f表示不放大缩小
        mLineChart.zoom(ratio, 1f, 0, 0);
        //设置从X轴出来的动画时间
        //mLineChart.animateX(1500);
        //设置XY轴动画
        mLineChart.animateXY(1500, 1500, Easing.EasingOption.EaseInSine, Easing.EasingOption.EaseInSine);

    }

    private void setChartXAxis(IAxisValueFormatter xValueFormatter) {

        XAxis xAxis = mLineChart.getXAxis();
        //设置字体大小
        xAxis.setTextSize(8f);
        xAxis.setTextColor(Color.parseColor("#000000"));
        //设置从x轴发出的横线
      /*  xAxis.setDrawGridLines(false);
        xAxis.setGridColor(Color.GRAY);*/
        //设置网格线宽度
        /*  xAxis.setGridLineWidth(1);*/
        //设置显示X轴
        xAxis.setDrawAxisLine(true);
        //设置X轴显示的位置
        xAxis.setPosition(XAxis.XAxisPosition.BOTTOM);
        //设置自定义X轴值
        xAxis.setValueFormatter(xValueFormatter);
        //一个界面显示6个Lable，那么这里要设置11个
        xAxis.setLabelCount(12);
        //设置最小间隔，防止当放大时出现重复标签
        xAxis.setGranularity(1f);
        //设置为true当一个页面显示条目过多，X轴值隔一个显示一个
        xAxis.setGranularityEnabled(true);
        //设置X轴的颜色
        xAxis.setAxisLineColor(Color.parseColor("#000000"));
        //设置X轴的宽度
        xAxis.setAxisLineWidth(1f);

        mLineChart.invalidate();
    }

    private void setChartYAxis() {
        //设置y轴
        YAxis leftAxis = mLineChart.getAxisLeft();
        //设置从Y轴发出横向直线(网格线)
        leftAxis.setDrawGridLines(true);
        //设置网格线的颜色
        leftAxis.setGridColor(Color.GRAY);
        //设置网格线宽度*/
        leftAxis.setGridLineWidth(1);
        //设置Y轴最小值是0，从0开始
        leftAxis.setAxisMinimum(0f);
        leftAxis.setGranularityEnabled(true);
        //设置最小间隔，防止当放大时出现重复标签
        leftAxis.setGranularity(1f);
        //如果沿着轴线的线应该被绘制，则将其设置为true,隐藏Y轴
        leftAxis.setDrawAxisLine(false);
        leftAxis.setDrawZeroLine(false);
        leftAxis.setTextSize(10f);
        leftAxis.setTextColor(Color.parseColor("#000000"));
        //设置左边X轴显示
        leftAxis.setEnabled(true);
        //设置Y轴的颜色
        leftAxis.setAxisLineColor(Color.parseColor("#000000"));
        //设置Y轴的宽度
        leftAxis.enableGridDashedLine(10f, 10f, 0f);//设置网格为虚线
        leftAxis.setAxisLineWidth(1f);
        leftAxis.setLabelCount(12);
        YAxis rightAxis = mLineChart.getAxisRight();
        rightAxis.setLabelCount(12);
        //设置右边Y轴不显示
        rightAxis.setEnabled(false);
    }

    private void setData1(ArrayList<String> xValueList, ArrayList<Float> yValuelLst,String label) {
        ArrayList<Entry> yValues = new ArrayList<>();
        for (int i = 0; i < xValueList.size(); i++) {
            yValues.add(new Entry(i, yValuelLst.get(i)));
        }
        LineDataSet set;
        if (mLineChart.getData() != null && mLineChart.getData().getDataSetCount() > 0) {
            set = (LineDataSet) mLineChart.getData().getDataSetByIndex(0);
            set.setValues(yValues);
            mLineChart.getData().notifyDataChanged();
            mLineChart.notifyDataSetChanged();
        } else {

            //设置值给图表
            set = new LineDataSet(yValues, label);
            //设置图标不显示
            set.setDrawIcons(true);
            //设置Y值使用左边Y轴的坐标值
            set.setAxisDependency(YAxis.AxisDependency.LEFT);
            //设置线的颜色
            set.setColors(Color.BLACK);
            //设置数据点圆形的颜色
            set.setCircleColor(Color.BLUE);
            //设置填充圆形中间的颜色
            set.setCircleColorHole(Color.BLACK);
            //设置折线宽度
            set.setLineWidth(1f);
            //设置折现点圆点半径
            set.setCircleRadius(4f);
            //设置十字线颜色
            //set.setHighLightColor(Color.parseColor("#47DBCC"));
            //设置显示十字线，必须显示十字线，否则MarkerView不生效
            set.setHighlightEnabled(true);
            //设置是否在数据点中间显示一个孔
            set.setDrawCircleHole(false);
            //设置填充
            //设置允许填充
            set.setDrawFilled(true);
            set.setFillAlpha(50);
            //设置背景渐变
            if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR2) {
                //设置渐变
                //设置渐变
              /*  Drawable drawable = ContextCompat.getDrawable(this, R.drawable.bg_gradient_color);
                set.setFillDrawable(drawable);*/

                set.setFillColor(Color.parseColor("#0E7AD4"));
            } else {
                set.setFillColor(Color.parseColor("#0E7AD4"));
            }

            LineData data = new LineData(set);
            //设置显示数据点的值
            data.setDrawValues(true);

            mLineChart.setData(data);
            mLineChart.invalidate();
        }
    }

}
